﻿namespace JunFan.Tests.UnitTests
{
    using System;
    using Domain;
    using FluentAssertions;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Infrastructure;

    [TestClass]
    public class CompletingItem
    {
        [TestInitialize]
        public void InitializeBoard()
        {
            UnitTestContext.InitBoard();
        }

        /// <summary>
        /// Given: An existent item, not completed.
        /// When: Completing it without complete date
        /// Then: Completed date should equal Today
        /// </summary>
        [TestMethod]
        public void WithoutCompleteDateShouldBeCompletedWithToday()
        {
            var nonCompletedItem = Given.NewItem.Added(UnitTestContext.Board);

            var completedItem = When.CompletingItem(nonCompletedItem.InternalId);

            completedItem.CompletedOn.Should().Be(DateTime.Today);
        }

        /// <summary>
        /// Given: An existent item, not completed.
        /// When: Completing it with a complete date
        /// Then: Completed date should equal the given date
        /// </summary>
        [TestMethod]    
        public void ShouldBeCompletedWithCompleteDate()
        {
            DateTime completeDate = DateTime.Today.AddDays(-5);

            var nonCompletedItem = Given.NewItem.Added(UnitTestContext.Board);

            var completedItem = When.CompletingItem(nonCompletedItem.InternalId, completeDate);

            completedItem.CompletedOn.Should().Be(completeDate);
        }

        /// <summary>
        /// Given: A item id that doesnt exist
        /// When: Completing it
        /// Then: A WrongArgumentException exception is throw
        /// </summary>
        [TestMethod]
        public void ShouldFailIfItemIdDoesntExist()
        {
            int nonExistentId = Given.ItemIdThatDoesntExist;

            Action action = () => When.CompletingItem(nonExistentId);

            // Then
            action.ShouldThrow<WrongArgumentException>()
                  .WithMessage(string.Format("There isn't an Item with id '{0}'.", nonExistentId), ComparisonMode.EquivalentSubstring);
        }

    }
}